Skip to content

fix: enable decimal input in Number field#68

Merged
nicolas-jaussaud merged 2 commits intomainfrom
fix/number-field-decimal-support
Mar 16, 2026
Merged

fix: enable decimal input in Number field#68
nicolas-jaussaud merged 2 commits intomainfrom
fix/number-field-decimal-support

Conversation

@titus-toia
Copy link
Contributor

The Number component was rejecting decimal input due to two issues:

  1. No formatOptions passed to react-aria's useNumberFieldState and useNumberField, so the NumberParser rejected decimal characters during input validation.

  2. The <input> value was overridden with Number.isInteger(state.numberValue) ? state.numberValue : 0, which collapsed any non-integer to 0 — preventing the user from ever typing a decimal point.

Fix: pass memoized formatOptions with maximumFractionDigits: 10 to both hooks (must be memoized — react-stately uses reference equality), remove the value override so react-aria controls the input natively, and expose a step prop (default 1) for +/- button increment granularity.

The Number component was rejecting decimal input due to two issues:

1. No `formatOptions` passed to react-aria's `useNumberFieldState` and
   `useNumberField`, so the NumberParser rejected decimal characters
   during input validation.

2. The `<input>` value was overridden with `Number.isInteger(state.numberValue)
   ? state.numberValue : 0`, which collapsed any non-integer to 0 — preventing
   the user from ever typing a decimal point.

Fix: pass memoized `formatOptions` with `maximumFractionDigits: 10` to both
hooks (must be memoized — react-stately uses reference equality), remove the
value override so react-aria controls the input natively, and expose a `step`
prop (default 1) for +/- button increment granularity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@titus-toia
Copy link
Contributor Author

@nicolas-jaussaud uwu

Validate the decimal input fix with tests covering initial decimal
values (float and string), user-typed decimals, step increment
behavior via button clicks, and formatOptions truncation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nicolas-jaussaud nicolas-jaussaud merged commit 9341282 into main Mar 16, 2026
2 checks passed
@nicolas-jaussaud
Copy link
Contributor

^-^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants